package com.yykj.backstage.all.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.util.GsonUtil;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.HospitalAdminDTO;
import com.yykj.hospital.client.dto.HospitalAdminListDTO;
import com.yykj.hospital.client.feign.HospitalServerFeignClient;
import com.yykj.hospital.client.form.HospitalAdminEditForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/backstage/all")
@Api(tags = "系统管理")
@SuppressWarnings("unchecked")
public class HospitalAccountController {

    @PostMapping("/hospital/admin/edit")
    @ApiOperation("医院总管理员--添加修改")
    @ApiOperationSupport(ignoreParameters = {"roles","type"})
    public ResultVO<HospitalAdminDTO> addHospitalAdmin(@RequestBody HospitalAdminEditForm form){
        HospitalAdminDTO hospitalAdminDTO = feignClient.editAdmin(form);
        System.out.println(hospitalAdminDTO == null);
        log.info("hospitalAdminDTO = {}", GsonUtil.toJson(hospitalAdminDTO));
        return ResultVO.success(hospitalAdminDTO);
    }


    @DeleteMapping("/hospital/admin/delete/{adminId}")
    @ApiOperation("医院总管理员--删除")
    public ResultVO deleteAdmin(@PathVariable Integer adminId) {
        feignClient.deleteAdmin(adminId);
        return ResultVO.success();
    }

    @GetMapping("/hospital/admin/list")
    @ApiOperation("医院总管理员--列表")
    public ResultVO<List<HospitalAdminListDTO>> listHospitalAdmin(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                                  @RequestParam(name = "username",required = false) String username,
                                                                  @RequestParam(name = "keyword",required = false) String keyword ) {
        List<HospitalAdminListDTO> hospitalAdminListDTOS = feignClient.listHospitalAdmin(hospitalId, username, keyword);
        return ResultVO.success(hospitalAdminListDTOS);
    }

    private HospitalServerFeignClient feignClient;

    @Autowired
    public void setFeignClient(HospitalServerFeignClient feignClient) {
        this.feignClient = feignClient;
    }
}
